package com.platform.analysis.enums;

import com.platform.comm.constants.EnumOption;
import com.platform.comm.enums.IEnumOption;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author liujizheng
 * @version 1.0
 * @ClassName ComplexOperator
 * @Description 数据查询连接方法
 * @date 2021/9/30 11:03
 */
@EnumOption(name = "complexOperator")
public enum ComplexOperator implements IEnumOption<String> {
    /**
     * 且条件
     */
    AND("AND", "且条件"),
    /**
     * 或条件
     */
    OR("OR", "或条件");

    String code;
    String title;
    ComplexOperator(String code, String title) {
        this.code = code;
        this.title = title;
    }

    /**
     * 枚举项 “键”
     *
     * @return key 键
     */
    @Override
    public String key() {
        return name();
    }

    /**
     * 枚举项 “值”
     *
     * @return value 值
     */
    @Override
    public String value() {
        return title;
    }

    public String getCode() {
        return code;
    }

    /**
     * 枚举options
     *
     * @return 枚举项组成的map
     */
    @Override
    public Map<String, String> enums() {
        return Arrays.stream(values()).collect(Collectors.toMap(IEnumOption::key, IEnumOption::value));
    }

    public static ComplexOperator parse(String name) {
        if (AND.name().equalsIgnoreCase(name)) {
            return AND;
        } else if (OR.name().equalsIgnoreCase(name)) {
            return OR;
        } else {
            return null;
        }
    }
}
